package juc;

import java.util.concurrent.locks.ReentrantLock;

/**
 * <pre>类名: ReentrantLockTest</pre>
 * <pre>描述: ReentrantLock测试</pre>
 * <pre>版权: web_chen@163.com</pre>
 * <pre>日期: 2020/10/30 16:32</pre>
 * <pre>作者: chenwb</pre>
 */
public class ReentrantLockTest {

	private final ReentrantLock lock = new ReentrantLock();

	private int num;

	/**
	 * 将num增加count
	 * @param count
	 */
	public void addCount(int count) {
		lock.lock();
		try {
			for (int i = 0; i < count; i++) {
				num++;
			}
		} finally {
			lock.unlock();
		}
	}

	public static void main(String[] args) throws InterruptedException {
		ReentrantLockTest reentrantLockTest = new ReentrantLockTest();
		Thread thread1 = new Thread(()->reentrantLockTest.addCount(200000));
		Thread thread2 =new Thread(()->reentrantLockTest.addCount(200000));
		thread1.start();
		thread2.start();
		thread1.join();
		thread2.join();
		System.out.println(reentrantLockTest.num);
		int a = 0;
		int b = 1;
		int c = 2;
		a = b = c;
		System.out.println(a);
		System.out.println(b);
		System.out.println(c);
	}
}
